// funçoes

function msg_sistema(msg, tipo) {
    $('#msg_sistema').fadeOut("slow").removeClass('alert_info').removeClass('alert_warning').removeClass('alert_error').removeClass('alert_success').html();
    if (msg != '' && $.type(msg) != 'boolean') {
        $('#msg_sistema').removeClass('alert_info').removeClass('alert_warning').removeClass('alert_error').removeClass('alert_success').addClass('alert_' + tipo).fadeIn("slow").html(msg).delay(30000).fadeOut("slow");
        $('html, body').animate({
            scrollTop: 0
        }, 1000);
    }
}

var _uri = {
    total: function() {
        return
    },
    segment: function(a, b) {
        var u = _uri._split(a, b);
        if (u[(a - 1)] == undefined) {
            return null;
        } else {
            return u[(a - 1)];
        }
    },
    segment_array: function(a, b) {
        return _uri._split(a, b);
    },
    segment_string: function(a, b) {
        return _uri._split(a, b).nivel.join('/') + '/';
    },
    _split: function(a, b) {
        if (a == undefined || a == "" || a == 0) {
            return null;
        } else {
            var nova_url = new Array();
            var url = b;
            if (b == undefined || b == "" || b == 0) {
                url = location.href;
            }

            url = url.replace(base_url, "");
            return url.split("/");
        }
    }
}

var _validate = {
    _split: function(a, b) {
        return a.split(b);
    },
    _expression: function(a, b) {
        var ExpReg = new RegExp(b);
        if (a.search(ExpReg) < 0) {
            return false;
        } else {
            return true;
        }
    },
    registro: function(registro) {
        registro = String(registro);
        if (registro.length == 11) {
            var dc1 = registro.substr(9, 1);
            var dc2 = registro.substr(10, 1);
            registro = registro.split("");
            for (var i = 0; i < registro.length; i++) {
                registro[i] = parseInt(registro[i], 10);
            }
            var soma1 = ((registro[0] * 2) + (registro[1] * 3) + (registro[2] * 4) + (registro[3] * 5) + (registro[4] * 6) + (registro[5] * 7) + (registro[6] * 8) + (registro[7] * 9) + (registro[8] * 10));
            var mod_soma1 = soma1 % 11;
            if (mod_soma1 > 1) {
                mod_soma1 = 11 - mod_soma1;
            } else {
                mod_soma1 = 0;
            }
            var soma2 = ((mod_soma1 * 2 + registro[0] * 3 + registro[1] * 4 + registro[2] * 5 + registro[3] * 6 + registro[4] * 7 + registro[5] * 8 + registro[6] * 9 + registro[7] * 10 + registro[8] * 11));
            var mod_soma2 = soma2 % 11;
            if (mod_soma2 > 1) {
                mod_soma2 = 11 - mod_soma2;
            } else {
                mod_soma2 = 0;
            }
            if ((mod_soma1 == dc1) && (mod_soma2 == dc2)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    },
    data: function(date) {
        var array_data = new Array;
        var erro = true;
        if (_validate._expression(date, "(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}") == true) {
            array_data = _validate._split(date, '/')
            if (((array_data[1] == 4) || (array_data[1] == 6) || (array_data[1] == 9) || (array_data[1] == 11)) && (array_data[0] > 30)) {
                erro = false;
            } else {
                if (array_data[1] == 2) {
                    if ((array_data[0] > 28) && ((array_data[2] % 4) != 0)) {
                        erro = false;
                    }
                    if ((array_data[0] > 29) && ((array_data[2] % 4) == 0)) {
                        erro = false;
                    }
                }
            }
        }
        return erro;
    },
    hora: function(h) {
        var novaHora = _validate._split(h, ':')
        var retorno = true;
        if (h.length > 4) {
            var hora = (novaHora[0] == undefined || novaHora[0] == "" ? null : novaHora[0]);
            var minuto = (novaHora[1] == undefined || novaHora[1] == "" ? null : novaHora[1]);
            var segundo = (novaHora[2] == undefined || novaHora[2] == "" ? null : novaHora[2]);
            if (hora != null) {
                if ((hora >= 0) && (hora <= 23)) {
                    if (minuto != null) {
                        if ((minuto >= 0) && (minuto <= 59)) {
                            if (segundo != null) {
                                if ((segundo >= 0) && (segundo <= 59)) {
                                    retorno = true;
                                } else {
                                    retorno = false;
                                }
                            } else {
                                retorno = true;
                            }
                        } else {
                            retorno = false;
                        }
                    }
                } else {
                    retorno = false;
                }
            } else {
                retorno = false;
            }
        } else {
            retorno = false;
        }
        return retorno;
    },
    mac_address: function(string) {
        var erros = true;
        string = _validate._split(string, ":");
        if (string.length != 6) {
            erros = true;
        } else {
            $.each(string, function(a, b) {
                erros = _validate._expression(b, "/[0-9]|[a-fA-F]{2}/");
            });
        }
        return erros;
    },
    hora_maior: function(hora_inicio, hora_fim) {
        var hie = hora_inicio.split(":");
        var hies = (hie[2] == undefined ? 0 : hie[2]);
        var hi = new Date(1970, 1, 1, hie[0], hie[1], hies);
        var hfe = hora_fim.split(":");
        var hfes = (hfe[2] == undefined ? 0 : hfe[2]);
        var hf = new Date(1970, 1, 1, hfe[0], hfe[1], hfes);
        if (hi.getTime() > hf.getTime()) {
            return false;
        } else {
            return true;
        }
    },
    data_hora_maior: function(data_hora_inicio, data_hora_fim) {
        var di = data_hora_inicio.split(" ");
        var df = data_hora_fim.split(" ");
        if (_validate.data_maior(di[0], df[0]) == true) {
            if (_validate.hora_maior(di[1], df[1]) == true) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    },
    data_maior: function(data_inicio, data_fim) {
        var hie = data_inicio.split("/");
        var hies = (hie[2] == undefined ? 0 : hie[2]);
        var hi = new Date(hies, hie[1], hie[0]);
        var hfe = data_fim.split("/");
        var hfes = (hfe[2] == undefined ? 0 : hfe[2]);
        var hf = new Date(hfes, hfe[1], hfe[0]);
        if (hi.getTime() > hf.getTime()) {
            return false;
        } else {
            return true;
        }
    },
    texto_input: function(string) {
        var arrayNegado = new Array();
        var erro = 0;
        arrayNegado[0] = "'";
        arrayNegado[1] = '"';
        arrayNegado[2] = "?";
        arrayNegado[3] = "OR";
        arrayNegado[4] = "AND";
        arrayNegado[5] = "=";
        arrayNegado[6] = "!";
        arrayNegado[7] = "-";
        arrayNegado[8] = "+";
        arrayNegado[9] = "*";
        arrayNegado[10] = "\\";
        arrayNegado[11] = "/";
        arrayNegado[12] = ":";
        arrayNegado[13] = ";";
        arrayNegado[14] = ">";
        arrayNegado[15] = "<";
        arrayNegado[16] = "`";
        arrayNegado[17] = "'";
        arrayNegado[18] = "%";
        arrayNegado[19] = "&";
        arrayNegado[20] = "$";
        arrayNegado[21] = "#";
        arrayNegado[22] = "|";
        for (var i = 0; i < string.length; i++) {
            for (var j = 0; j < arrayNegado.length; j++) {
                if (string[i] == arrayNegado[j]) {
                    erro++;
                }
            }
        }
        return erro;
    },
    data_hora: function(data_hora) {
        var explode = data_hora.split(" ");
        var data = (explode[0] == undefined || explode[0] == "" ? null : explode[0]);
        var hora = (explode[1] == undefined || explode[1] == "" ? null : explode[1]);
        var retorno = false;
        if (data != null) {
            if (_validate.data($.trim(data)) == true) {
                retorno = true;
            }
        } else {
            retorno = true;
        }
        if (hora != null) {
            if (_validate.hora($.trim(hora)) == true) {
                retorno = true;
            }
        } else {
            retorno = true;
        }
        return retorno;
    },
    CPF: function(cpf) {
        var exp = /\.|\-/g;
        cpf = cpf.toString().replace(exp, "");
        var erro = false;
        var digitos_iguais = 1;
        if (cpf.length != 11) {
            erro = true;
        } else {
            if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") {
                erro = true;
            } else {
                for (i = 0; i < cpf.length - 1; i++) {
                    if (cpf.charAt(i) != cpf.charAt(i + 1)) {
                        digitos_iguais = 0;
                        break;
                    }
                }
                if (!digitos_iguais) {
                    var numeros = cpf.substring(0, 9);
                    var digitos = cpf.substring(9);
                    var soma = 0;
                    for (i = 10; i > 1; i--) {
                        soma += numeros.charAt(10 - i) * i;
                    }
                    var resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                    if (resultado != digitos.charAt(0)) {
                        erro = true;
                    }
                    numeros = cpf.substring(0, 10);
                    soma = 0;
                    for (var i = 11; i > 1; i--) {
                        soma += numeros.charAt(11 - i) * i;
                    }
                    resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                    if (resultado != digitos.charAt(1)) {
                        erro = true;
                    } else {
                        erro = false;
                    }
                } else {
                    erro = true;
                }
            }
        }
        return erro;
    },
    CNPJ: function(cnpj) {
        var erro = false;
        var exp = /\.|\-|\//g;
        cnpj = cnpj.toString().replace(exp, "");
        if (cnpj.length != 14) {
            erro = true;
        } else {
            if (cnpj == "00000000000000" || cnpj == "11111111111111" || cnpj == "22222222222222" || cnpj == "33333333333333" || cnpj == "44444444444444" || cnpj == "55555555555555" || cnpj == "66666666666666" || cnpj == "88888888888888" || cnpj == "99999999999999") {
                erro = true;
            } else {
                var valida = new Array(6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2);
                var dig1 = new Number;
                var dig2 = new Number;
                var digito = new Number(eval(cnpj.charAt(12) + cnpj.charAt(13)));
                for (i = 0; i < valida.length; i++) {
                    dig1 += (i > 0 ? (cnpj.charAt(i - 1) * valida[i]) : 0);
                    dig2 += cnpj.charAt(i) * valida[i];
                }
                dig1 = (((dig1 % 11) < 2) ? 0 : (11 - (dig1 % 11)));
                dig2 = (((dig2 % 11) < 2) ? 0 : (11 - (dig2 % 11)));
                if (((dig1 * 10) + dig2) != digito) {
                    erro = true;
                }
            }
        }
        return erro;
    },
    email: function(mail) {
        var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        if (er.test(mail)) {
            return true;
        } else {
            return false;
        }
    }
}

function number_format(number, decimals, dec_point, thousands_sep) {
    var n = number, prec = decimals;
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep == "undefined") ? "," : thousands_sep;
    var dec = (typeof dec_point == "undefined") ? "." : dec_point;
    var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec);
    var abs = Math.abs(n).toFixed(prec);
    var _, i;
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
        _[0] = s.slice(0, i + (n < 0)) + _[0].slice(i).replace(/(\d{3})/g, sep + "$1");
        s = _.join(dec);
    } else {
        s = s.replace(".", dec);
    }
    return s;
}

function converter_moeda(str, sub1, sub2) {
    if (sub1 == undefined) {
        sub1 = ",";
    }
    if (sub2 == undefined) {
        sub2 = ".";
    }
    var numero = str.split(".");
    var numero_novo = "";
    for (var i = 0; i < numero.length; i++) {
        numero_novo += numero[i];
    }
    numero_novo = numero_novo.replace(sub1, sub2);
    return parseFloat(numero_novo);
}

function rgb_2_hex(a) {
    if (!$.browser.msie) {
        var d = a.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
        if (d != null) {
            function b(c) {
                return ("0" + parseInt(c).toString(16)).slice(-2);
            }

            return "#" + b(d[1]) + b(d[2]) + b(d[3]);
        } else {
            return a;
        }
    } else {
        return a;
    }
}

function mascara(str, formato) {
    if (str.length > formato.length) {
        return false;
    } else {
        var saida = "";
        var cont = 0;
        for (var i = 0; i < formato.length; i++) {
            if (formato[i] == "9") {
                saida += str[cont];
                cont++;
            } else {
                saida += formato[i];
            }
        }
        return saida;
    }
}

function formata_data(data) {
    var dt = data.split("-");
    return dt[2] + "/" + dt[1] + "/" + dt[0];
}

function limpa_string(str) {
    if (str) {
        var novo_str = "";
        novo_str = str.replaceAll("(", "");
        novo_str = novo_str.replaceAll(")", "");
        novo_str = novo_str.replaceAll('"', "");
        novo_str = novo_str.replaceAll("'", "");
        novo_str = novo_str.replaceAll("-", "");
        novo_str = novo_str.replaceAll("_", "");
        novo_str = novo_str.replaceAll(":", "");
        novo_str = novo_str.replaceAll("[", "");
        novo_str = novo_str.replaceAll("]", "");
        novo_str = novo_str.replaceAll("{", "");
        novo_str = novo_str.replaceAll("}", "");
        novo_str = novo_str.replaceAll("&", "");
        novo_str = novo_str.replaceAll("%", "");
        novo_str = novo_str.replaceAll("$", "");
        novo_str = novo_str.replaceAll("#", "");
        novo_str = novo_str.replaceAll("@", "");
        novo_str = novo_str.replaceAll(" ", "");
        return novo_str;
    } else {
        return "";
    }
}

// plugins
$.fn.serializeObject = function() {
    var o = {};

    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || "");
        } else {
            o[this.name] = this.value || "";
        }
    });
    return o;
};

(function($) {
    $.fn.tipTip = function(options) {
        var defaults = {
            activation: "hover",
            keepAlive: false,
            maxWidth: "200px",
            edgeOffset: 3,
            defaultPosition: "bottom",
            delay: -100,
            fadeIn: -200,
            fadeOut: -200,
            attribute: "title",
            content: false,
            enter: function() {
            },
            exit: function() {
            }
        };

        var opts = $.extend(defaults, options);
        if ($("#tiptip_holder").length <= 0) {
            var tiptip_holder = $('<div id="tiptip_holder" style="max-width:' + opts.maxWidth + ';"></div>');
            var tiptip_content = $('<div id="tiptip_content"></div>');
            var tiptip_arrow = $('<div id="tiptip_arrow"></div>');
            $("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')));
        } else {
            var tiptip_holder = $("#tiptip_holder");
            var tiptip_content = $("#tiptip_content");
            var tiptip_arrow = $("#tiptip_arrow");
        }
        return this.each(function() {
            var org_elem = $(this);
            if (opts.content) {
                var org_title = opts.content;
            } else {
                var org_title = org_elem.attr(opts.attribute);
            }
            if (org_title != "") {
                if (!opts.content) {
                    org_elem.removeAttr(opts.attribute);
                }
                var timeout = false;
                if (opts.activation == "hover") {
                    org_elem.hover(function() {
                        active_tiptip();
                    }, function() {
                        if (!opts.keepAlive) {
                            deactive_tiptip();
                        }
                    });
                    if (opts.keepAlive) {
                        tiptip_holder.hover(function() {
                        }, function() {
                            deactive_tiptip();
                        });
                    }
                } else {
                    if (opts.activation == "focus") {
                        org_elem.focus(function() {
                            active_tiptip();
                        }).blur(function() {
                            deactive_tiptip();
                        });
                    } else {
                        if (opts.activation == "click") {
                            org_elem.click(function() {
                                active_tiptip();
                                return false;
                            }).hover(function() {
                            }, function() {
                                if (!opts.keepAlive) {
                                    deactive_tiptip();
                                }
                            });
                            if (opts.keepAlive) {
                                tiptip_holder.hover(function() {
                                }, function() {
                                    deactive_tiptip();
                                });
                            }
                        }
                    }
                }
                function active_tiptip() {
                    opts.enter.call(this);
                    tiptip_content.html(org_title);
                    tiptip_holder.hide().removeAttr("class").css("margin", "0");
                    tiptip_arrow.removeAttr("style");
                    var top = parseInt(org_elem.offset()["top"]);
                    var left = parseInt(org_elem.offset()["left"]);
                    var org_width = parseInt(org_elem.outerWidth());
                    var org_height = parseInt(org_elem.outerHeight());
                    var tip_w = tiptip_holder.outerWidth();
                    var tip_h = tiptip_holder.outerHeight();
                    var w_compare = Math.round((org_width - tip_w) / 2);
                    var h_compare = Math.round((org_height - tip_h) / 2);
                    var marg_left = Math.round(left + w_compare);
                    var marg_top = Math.round(top + org_height + opts.edgeOffset);
                    var t_class = "";
                    var arrow_top = "";
                    var arrow_left = Math.round(tip_w - 12) / 2;
                    if (opts.defaultPosition == "bottom") {
                        t_class = "_bottom";
                    } else {
                        if (opts.defaultPosition == "top") {
                            t_class = "_top";
                        } else {
                            if (opts.defaultPosition == "left") {
                                t_class = "_left";
                            } else {
                                if (opts.defaultPosition == "right") {
                                    t_class = "_right";
                                }
                            }
                        }
                    }
                    var right_compare = (w_compare + left) < parseInt($(window).scrollLeft());
                    var left_compare = (tip_w + left) > parseInt($(window).width());
                    if ((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))) {
                        t_class = "_right";
                        arrow_top = Math.round(tip_h - 13) / 2;
                        arrow_left = -12;
                        marg_left = Math.round(left + org_width + opts.edgeOffset);
                        marg_top = Math.round(top + h_compare);
                    } else {
                        if ((left_compare && w_compare < 0) || (t_class == "_left" && !right_compare)) {
                            t_class = "_left";
                            arrow_top = Math.round(tip_h - 13) / 2;
                            arrow_left = Math.round(tip_w);
                            marg_left = Math.round(left - (tip_w + opts.edgeOffset + 5));
                            marg_top = Math.round(top + h_compare);
                        }
                    }
                    var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop());
                    var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0;
                    if (top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)) {
                        if (t_class == "_top" || t_class == "_bottom") {
                            t_class = "_top";
                        } else {
                            t_class = t_class + "_top";
                        }
                        arrow_top = tip_h;
                        marg_top = Math.round(top - (tip_h + 5 + opts.edgeOffset));
                    } else {
                        if (bottom_compare | (t_class == "_top" && bottom_compare) || (t_class == "_bottom" && !top_compare)) {
                            if (t_class == "_top" || t_class == "_bottom") {
                                t_class = "_bottom";
                            } else {
                                t_class = t_class + "_bottom";
                            }
                            arrow_top = -12;
                            marg_top = Math.round(top + org_height + opts.edgeOffset);
                        }
                    }
                    if (t_class == "_right_top" || t_class == "_left_top") {
                        marg_top = marg_top + 5;
                    } else {
                        if (t_class == "_right_bottom" || t_class == "_left_bottom") {
                            marg_top = marg_top - 5;
                        }
                    }
                    if (t_class == "_left_top" || t_class == "_left_bottom") {
                        marg_left = marg_left + 5;
                    }
                    tiptip_arrow.css({
                        "margin-left": arrow_left + "px",
                        "margin-top": arrow_top + "px"
                    });
                    tiptip_holder.css({
                        "margin-left": marg_left + "px",
                        "margin-top": marg_top + "px"
                    }).attr("class", "tip" + t_class);
                    if (timeout) {
                        clearTimeout(timeout);
                    }
                    timeout = setTimeout(function() {
                        tiptip_holder.stop(true, true).fadeIn(opts.fadeIn);
                    }, opts.delay);
                }

                function deactive_tiptip() {
                    opts.exit.call(this);
                    if (timeout) {
                        clearTimeout(timeout);
                    }
                    tiptip_holder.fadeOut(opts.fadeOut);
                }

            }
        });
    };

})(jQuery);

(function($) {
    $.fn.extend({
        subtitulo: function(parametros) {
            var defaults = {
                msg: "",
                css: {}
            };

            var options = $.extend(true, defaults, parametros);
            $(this).after('<span class="exemplo_span">' + options.msg + "</span>");
            $(this).next().css(options.css);
            return false;
        }
    });
})(jQuery);

$.fn.selectRange = function(d, a) {
    var c = document.getElementById($(this).attr("id"));
    if (!c) {
        return;
    } else {
        if (c.setSelectionRange) {
            c.focus();
            c.setSelectionRange(d, a);
        } else {
            if (c.createTextRange) {
                var b = c.createTextRange();
                b.collapse(true);
                b.moveEnd("character", a);
                b.moveStart("character", d);
                b.select();
            } else {
                if (c.selectionStart) {
                    c.selectionStart = d;
                    c.selectionEnd = a;
                }
            }
        }
    }
};

new function(a) {
    a.fn.setCursorPosition = function(c) {
        if (a(this).get(0).setSelectionRange) {
            a(this).get(0).setSelectionRange(c, c);
        } else {
            if (a(this).get(0).createTextRange) {
                var b = a(this).get(0).createTextRange();
                b.collapse(true);
                b.moveEnd("character", c);
                b.moveStart("character", c);
                b.select();
            }
        }
    };

}(jQuery);

(function($) {
    $.fn.extend({
        form_validate: function(parametros) {
            var defaults = {
                class_erro: "textoErro",
                class_sucesso: "textoSucesso",
                class_aviso: "textoAviso",
                class_desabilitado: "textoDisabled",
                msg: "Os campos destacados em vermelho, são de preenchimento obrigatório ou contém erros.",
                success: function(a, b, c) {
                },
                error: function(a, b, c) {
                }
            };

            var options = $.extend(true, defaults, parametros);
            var obj = this;
            var erro = 0;
            var campo_focus = "";
            $(".ui-tabs-nav li").css("background", "").removeAttr("title");
            $.each($(this).find(":input"), function() {
                $(this).removeClass(options.class_sucesso);
                $(this).removeClass(options.class_erro);
                $(this).removeClass(options.class_aviso);
                $(this).removeAttr("title");
                if ($(this).hasClass("obrigatorio") && $.trim($(this).val()) == "") {
                    erro++;
                    $(this).attr("title", "Campo obrigatório");
                    $(this).addClass(options.class_erro);
                } else if ($.trim($(this).val()) != "") {
                    if ($(this).hasClass("data")) {
                        if (_validate.data($.trim($(this).val())) == false) {
                            erro++;
                            $(this).prop("title", "Data inválida");
                            $(this).addClass(options.class_erro);
                        } else if ($(this).prop("cmp") != undefined) {
                            var cmp_id = "#" + $(this).attr("cmp");
                            if ($(obj).find(cmp_id).val() != "") {
                                if (_validate.data_maior($(obj).find(cmp_id).val(), $(this).val()) == false) {
                                    erro++;
                                    $(this).attr("title", "Data fim menor que Data início");
                                    $(this).addClass(options.class_erro);
                                } else {
                                    $(this).addClass(options.class_sucesso);
                                }
                            }
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if (($(this).hasClass("hora") || $(this).hasClass("hora_segundos"))) {
                        if (_validate.hora($.trim($(this).val())) == false) {
                            erro++;
                            $(this).attr("title", "Hora inválida");
                            $(this).addClass(options.class_erro);
                        } else if ($(this).prop("cmp") != undefined) {
                            var cmp_id = "#" + $(this).attr("cmp");
                            if ($(obj).find(cmp_id).val() != "") {
                                if (_validate.hora_maior($(obj).find(cmp_id).val(), $(this).val()) == false) {
                                    erro++;
                                    $(this).attr("title", "Hora fim menor que Hora início");
                                    $(this).addClass(options.class_erro);
                                } else {
                                    $(this).addClass(options.class_sucesso);
                                }
                            }
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if ($(this).hasClass("data_hora")) {
                        if (_validate.data_hora($.trim($(this).val())) == false) {
                            erro++;
                            $(this).attr("title", "Data/Hora inválida");
                            $(this).addClass(options.class_erro);
                        } else if ($(this).prop("cmp") != undefined) {
                            var cmp_id = "#" + $(this).prop("cmp");
                            if ($(obj).find(cmp_id).val() != "") {
                                if (_validate.data_hora_maior($(obj).find(cmp_id).val(), $(this).val()) == false) {
                                    erro++;
                                    $(this).attr("title", "Data Hora fim menor que Data Hora início");
                                    $(this).addClass(options.class_erro);
                                } else {
                                    $(this).addClass(options.class_sucesso);
                                }
                            }
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if ($(this).hasClass("cpf")) {
                        if (_validate.CPF($.trim($(this).val())) == true) {
                            erro++;
                            $(this).attr("title", "CPF inválido");
                            $(this).addClass(options.class_erro);
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if ($(this).hasClass("cpf_cnpj")) {
                        if ($.trim($(this).val()).length == 14) {
                            if (_validate.CPF($.trim($(this).val())) == true) {
                                erro++;
                                $(this).attr("title", "CPF inválido");
                                $(this).addClass(options.class_erro);
                            } else {
                                $(this).addClass(options.class_sucesso);
                            }
                        } else {
                            if (_validate.CNPJ($.trim($(this).val())) == true) {
                                erro++;
                                $(this).attr("title", "CNPJ inválido");
                                $(this).addClass(options.class_erro);
                            } else {
                                $(this).addClass(options.class_sucesso);
                            }
                        }
                    } else if ($(this).hasClass("mac")) {
                        if (_validate.mac_address($.trim($(this).val())) == true) {
                            erro++;
                            $(this).attr("title", "MAC inválido");
                            $(this).addClass(options.class_erro);
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if ($(this).hasClass("placa")) {
                        if ($.trim($(this).val()).length != 8) {
                            erro++;
                            $(this).attr("title", "Placa inválido");
                            $(this).addClass(options.class_erro);
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if ($(this).hasClass("cnpj")) {
                        if (_validate.CNPJ($.trim($(this).val())) == true) {
                            erro++;
                            $(this).attr("title", "CNPJ inválido");
                            $(this).addClass(options.class_erro);
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if ($(this).hasClass("email")) {
                        if (_validate.email($.trim($(this).val())) == false) {
                            erro++;
                            $(this).attr("title", "E-mail inválido");
                            $(this).addClass(options.class_erro);
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if ($(this).hasClass("telefone")) {
                        if ($.trim($(this).val()).length < 14 && $.trim($(this).val()).length > 16) {
                            erro++;
                            $(this).attr("title", "Formato do telefone inválido");
                            $(this).addClass(options.class_erro);
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else if ($(this).hasClass("pais_telefone")) {
                        if ($.trim($(this).val()).length < 18 && $.trim($(this).val()).length > 20) {
                            erro++;
                            $(this).attr("title", "Formato do telefone inválido");
                            $(this).addClass(options.class_erro);
                        } else {
                            $(this).addClass(options.class_sucesso);
                        }
                    } else {
                        $(this).addClass(options.class_sucesso);
                    }
                }
                if (erro != 0) {
                    if (campo_focus == "") {
                        campo_focus = $(this);
                    }
                    if ($(".ui-tabs-nav").html() != null) {
                        if ($(this).hasClass(options.class_erro)) {
                            var id_tabs = $(this).closest(".ui-tabs-panel").prop("id");
                            $('.ui-tabs-nav li a[href="#' + id_tabs + '"]').attr("title", "A erro(s) no(s) campo(s) desta aba.").closest("li").css("background", "#F6BEC1");
                        }
                    }
                }
            });
            if (erro > 0) {
                options.error.call(null, $.parseJSON('{"cod":"404","msg":"Error: ' + options.msg + '"}'), obj, options);
                campo_focus.focus();
                return false;
            } else {
                options.success.call(null, {}, obj, options);
                return true;
            }
        }
    });
})(jQuery);

(function($) {
    $.fn.extend({
        form_color: function(parametros) {
            var defaults = {
                class_erro: "textoErro",
                class_sucesso: "textoSucesso",
                class_aviso: "textoAviso",
                campos: ""
            };

            var options = $.extend(true, defaults, parametros);
            var obj = $(this);
            var meuArray = new Array();
            $(".ui-tabs-nav li").css("background", "").removeAttr("title");
            $.each(options.campos, function(a, b) {
                meuArray[a] = b;
            });
            $.each(obj.find(":input"), function(c, d) {
                if (meuArray[$(d).attr("id")]) {
                    var b = meuArray[$(d).attr("id")];
                    var id_tbl = "#" + $(d).attr("id") + "_tbl";
                    $(d).removeClass(options.class_sucesso);
                    $(d).removeClass(options.class_erro);
                    $(d).removeClass(options.class_aviso);
                    $(d).removeAttr("title");
                    $(id_tbl).removeAttr("title");
                    $(id_tbl).removeClass(options.class_sucesso);
                    $(id_tbl).removeClass(options.class_aviso);
                    $(id_tbl).removeClass(options.class_erro);
                    $(d).addClass(options.class_erro);
                    $(id_tbl).addClass(options.class_erro);
                    $(d).attr("title", b.ASCIIDecode());
                    $(id_tbl).attr("title", b.ASCIIDecode());
                    if ($(".ui-tabs-nav").html() != null) {
                        if ($(d).hasClass(options.class_erro)) {
                            var id_tabs = $(d).closest(".ui-tabs-panel").attr("id");
                            $('.ui-tabs-nav li a[href="#' + id_tabs + '"]').attr("title", "A erro(s) no(s) campo(s) desta aba.").closest("li").css("background", "#F6BEC1");
                        }
                    }
                }
            });
        }
    });
})(jQuery);

(function($) {
    $.fn.extend({
        form_clear: function() {
            $(this).find(":input").each(function() {
                switch (this.type) {
                    case"password":
                    case"select-multiple":
                    case"select-one":
                    case"select":
                    case"text":
                    case"textarea":
                        $(this).val("");
                        break;
                    case"checkbox":
                    case"radio":
                        this.checked = false;
                        break;
                }
            });
        }
    });
})(jQuery);

(function($) {
    $.fn.extend({
        set_mascara: function(parametros) {
            var defaults = {
                numero: {
                    size: 10,
                    maxlength: 10,
                    minDate: null,
                    mascara: "?9999999999"
                },
                alfa: {
                    size: 4,
                    maxlength: 3,
                    mascara: "?aaa",
                    titulo: "Informe somente caracters alfa"
                }
            };

            var options = $.extend(true, defaults, parametros);
            $.each($(this).find(":input"), function() {
                $(this).unmask();
                $(this).unmaskMoney();
                if ($(this).hasClass("textoDisabled")) {
                    $(this).removeAttr("title");
                    $(this).removeClass("obrigatorio");
                }
                if ($(this).hasClass("obrigatorio")) {
                    $(this).removeAttr("title");
                }
                if ($(this).attr("disabled")) {
                    $(this).addClass("textoDisabled");
                }
                if ($(this).hasClass("data")) {
                    $(this).mask("?99/99/9999");
                    $(this).datepicker({
                        minDate: options.minDate
                    });
                    $(this).attr("title", "Informe uma Data");
                    $(this).attr("size", "10");
                    $(this).attr("maxlength", "10");
                } else if ($(this).hasClass("mes_data")) {
                    $(this).mask("?99/9999");
                    $(this).attr("title", "Informe uma Mês e Ano");
                    $(this).attr("size", "7");
                    $(this).attr("maxlength", "7");
                } else if ($(this).hasClass("email")) {
                    $(this).attr("title", "Informe um E-mail.");
                } else if ($(this).hasClass("hora")) {
                    $(this).attr("title", "Informe uma Hora.");
                    $(this).mask("?99:99");
                    $(this).attr("size", "5");
                    $(this).attr("maxlength", "5");
                } else if ($(this).hasClass("hora_label")) {
                    $(this).attr("title", "Informe uma Hora.");
                    $(this).mask("?99:99");
                    $(this).attr("size", "5");
                    $(this).attr("maxlength", "5");
                } else if ($(this).hasClass("hora_segundos")) {
                    $(this).mask("?99:99:99");
                    $(this).attr("title", "Informe uma Hora.");
                    $(this).attr("size", "8");
                    $(this).attr("maxlength", "8");
                } else if ($(this).hasClass("data_hora")) {
                    $(this).datetimepicker({
                        showSecond: true,
                        timeFormat: "hh:mm:ss"
                    });
                    $(this).mask("?99/99/9999 99:99:99");
                    $(this).attr("title", "Informe uma Data/Hora.");
                    $(this).attr("size", "20");
                    $(this).attr("maxlength", "19");
                } else if ($(this).hasClass("data_hora_segundos")) {
                    $(this).datetimepicker({
                        showSecond: true,
                        timeFormat: "hh:mm"
                    });
                    $(this).mask("?99/99/9999 99:99");
                    $(this).attr("title", "Informe uma Data/Hora.");
                    $(this).attr("size", "18");
                    $(this).attr("maxlength", "16");
                } else if ($(this).hasClass("placa")) {
                    $(this).mask("?aaa-9999");
                    $(this).attr("title", "Informe uma Placa.");
                    $(this).attr("size", "8");
                    $(this).attr("maxlength", "8");
                    $(this).css({
                        "text-transform": "uppercase"
                    });
                } else if ($(this).hasClass("cpf")) {
                    $(this).mask("?999.999.999-99");
                    $(this).attr("title", "Informe um CPF.");
                    $(this).attr("size", "14");
                    $(this).attr("maxlength", "14");
                } else if ($(this).hasClass("cpf_cnpj")) {
                    $(this).mask("?99.999.999/9999-99").live("focusout", function(event) {
                        var target, phone, element;
                        target = (event.currentTarget) ? event.currentTarget : event.srcElement;
                        phone = target.value.replace(/\D/g, "");
                        element = $(target);
                        element.unmask();
                        if (phone.length > 11) {
                            element.attr("title", "Informe um CNPJ.");
                            element.attr("size", "18");
                            element.attr("maxlength", "18");
                            element.mask("?99.999.999/9999-99");
                        } else {
                            element.mask("?999.999.999-99");
                            element.attr("title", "Informe um CPF.");
                            element.attr("size", "14");
                            element.attr("maxlength", "14");
                        }
                    });
                } else if ($(this).hasClass("mac")) {
                    $(this).mask("?**:**:**:**:**:**").css({
                        "text-transform": "uppercase"
                    });
                    $(this).attr("title", "Informe um CPF.");
                    $(this).attr("size", "18");
                    $(this).attr("maxlength", "17");
                } else if ($(this).hasClass("ddd")) {
                    $(this).mask("?99");
                    $(this).attr("title", "Informe um DDD.");
                    $(this).attr("size", "2");
                    $(this).attr("maxlength", "2");
                } else if ($(this).hasClass("telefone")) {
                    $(this).mask("?(99) 9999-99999").live("focusout", function(event) {
                        var target, phone, element;
                        target = (event.currentTarget) ? event.currentTarget : event.srcElement;
                        phone = target.value.replace(/\D/g, "");
                        element = $(target);
                        element.unmask();
                        if (phone.substr(0, 2) == '11') {
                            element.mask("?(99) 99999-9999");
                        } else {
                            element.mask("?(99) 9999-9999");
                        }
                    });
                    $(this).attr("title", "Informe um Telefone com DDD.");
                    $(this).attr("size", "16");
                    $(this).attr("maxlength", "14");
                } else if ($(this).hasClass("pais_telefone")) {
                    $(this).mask("?+99 (99) 9999-9999?9").live("focusout", function(event) {
                        var target, phone, element;
                        target = (event.currentTarget) ? event.currentTarget : event.srcElement;
                        phone = target.value.replace(/\D/g, "");
                        element = $(target);
                        element.unmask();
                        if (phone.substr(2, 2) == '11') {
                            element.mask("?+99 (99) 99999-9999");
                        } else {
                            element.mask("?+99 (99) 9999-9999");
                        }
                    });
                    $(this).attr("title", "Informe um Telefone com DDD.");
                    $(this).attr("size", "20");
                    $(this).attr("maxlength", "18");
                } else if ($(this).hasClass("cnpj")) {
                    $(this).mask("?99.999.999/9999-99");
                    $(this).attr("title", "Informe um CNPJ.");
                    $(this).attr("size", "18");
                    $(this).attr("maxlength", "18");
                } else if ($(this).hasClass("pis")) {
                    $(this).mask("?999.99999.99-9");
                    $(this).attr("title", "Informe um PIS.");
                    $(this).attr("size", "15");
                    $(this).attr("maxlength", "14");
                } else if ($(this).hasClass("ctps")) {
                    $(this).mask("?9999999");
                    $(this).attr("title", "Informe um CPTS.");
                    $(this).attr("size", "8");
                    $(this).attr("maxlength", "7");
                } else if ($(this).hasClass("ctps_serie")) {
                    $(this).mask("?99999");
                    $(this).attr("title", "Informe a série.");
                    $(this).attr("size", "6");
                    $(this).attr("maxlength", "5");
                } else if ($(this).hasClass("cep")) {
                    $(this).mask("?99999-999");
                    $(this).attr("title", "Informe um CEP.");
                    $(this).attr("size", "9");
                    $(this).attr("maxlength", "9");
                } else if ($(this).hasClass("endereco_numero")) {
                    $(this).mask("?9999999999", {
                        placeholder: ""
                    });
                    $(this).attr("title", "Informe o número.");
                    $(this).attr("size", "10");
                    $(this).attr("maxlength", "10");
                } else if ($(this).hasClass("numero_versao")) {
                    $(this).mask("?99.99.99", {
                        placeholder: ""
                    });
                    $(this).attr("title", "Informe o número da versão.");
                    $(this).attr("size", "8");
                    $(this).attr("maxlength", "8");
                } else if ($(this).hasClass("numero")) {
                    $(this).mask(options.numero.mascara, {
                        placeholder: ""
                    });
                    $(this).attr("title", "Informe o número.");
                    $(this).attr("size", options.numero.size);
                    $(this).attr("maxlength", options.numero.maxlength);
                } else if ($(this).hasClass("alfa")) {
                    $(this).mask(options.alfa.mascara, {
                        placeholder: ""
                    });
                    $(this).attr("title", options.alfa.titulo);
                    $(this).attr("size", options.alfa.size);
                    $(this).attr("maxlength", options.alfa.maxlength);
                } else if ($(this).hasClass("peso")) {
                    $(this).maskMoney({
                        allowNegative: true,
                        precision: 3
                    });
                    $(this).attr("title", "Informe o peso.");
                } else if ($(this).hasClass("altura_largura")) {
                    $(this).maskMoney({
                        allowNegative: true,
                        precision: 2
                    });
                    $(this).attr("title", "Informe a (altura/largura).");
                } else if ($(this).hasClass("moeda")) {
                    $(this).maskMoney({
                        allowNegative: true
                    });
                    $(this).attr("title", "Informe valor Monetário.");
                } else if ($(this).hasClass("latitude_longitude")) {
                    $(this).maskMoney({
                        allowNegative: true,
                        precision: 6
                    });
                    $(this).attr("title", "Informe valor " + $(this).attr("name") + ".");
                } else if ($(this).hasClass("peso")) {
                    $(this).maskMoney({
                        precision: 3
                    });
                    $(this).attr("title", "Informe valor Peso KG");
                }
            });
            $.each($(this).find(":input"), function() {
                var concat = "";
                if ($(this).hasClass("obrigatorio")) {
                    concat = $(this).attr("title");
                    if (concat == undefined || $.trim(concat) == "") {
                        $(this).attr("title", "Campo obrigatório.");
                    } else {
                        $(this).attr("title", "Campo obrigatório, " + concat);
                    }
                } else {
                    if ($(this).hasClass("obrigatorio_tinymce")) {
                        concat = $(this).parent().attr("title");
                        if (concat == undefined || $.trim(concat) == "") {
                            $(this).parent().attr("title", "Campo obrigatório.");
                        } else {
                            $(this).parent().attr("title", "Campo obrigatório, " + concat);
                        }
                    }
                }
            });
        }
    });
})(jQuery);
/*
 (function($){
 $.fn.ceps=function(parametros){
 $(this).change(function(){
 var defaults={
 msg_busca:"Aguarde... Buscado dados do CEP.",
 tipo_consulta:"cep",
 success:function(){},
 error:function(){}
 };
 
 var obj=this;
 var retorno=null;
 var options=$.extend(true,defaults,parametros);
 if(options.tipo_consulta!=""){
 $.ajax({
 url:base_url+"busca_cep/"+options.tipo_consulta+"/"+$(obj).val()+"/json",
 dataType:"json",
 async:false,
 beforeSend:function(){
 msg_sistema(options.msg_busca,"aviso");
 },
 success:function(response){
 msg_sistema("","");
 if(response!=undefined&&response.length>0){
 retorno=response;
 retorna_cep();
 }else{
 retorna_cep();
 }
 }
 });
 }else{
 retorna_cep();
 }
 function retorna_cep(){
 var novo_retorno={};
 
 if(retorno!=null){
 options.success.call(novo_retorno,retorno[0]);
 }else{
 options.error.call(novo_retorno,$.parseJSON('{"cod":"404","msg":"CEP não localizado."}'));
 }
 return true;
 }
 });
 };
 
 })(jQuery);*/

(function($) {
    $.google_maps = function(parametros) {
        var defaults = {
            campos: {},
            success: function() {
            },
            error: function() {
            }
        };

        var novo_retorno = {};

        var options = $.extend(true, defaults, parametros);
        $.ajax({
            url: base_url + "google_maps/latitude_longitude/",
            dataType: "json",
            type: "POST",
            data: options.campos,
            success: function(response) {
                if (response.cod == 999) {
                    options.success.call(novo_retorno, response);
                } else {
                    options.error.call(novo_retorno, $.parseJSON('{"cod":"404","msg":"Latitude e Longitude não localizado."}'));
                }
            }
        });
    };

})(jQuery);

(function($) {
    $.fn.extend({
        print_frame: function(parametros) {
            var defaults = {
                html: "",
                height: ($(window).height() - ($(window).height() / 10)),
                width: ($(window).width() - 100),
                title: ""
            };

            var options = $.extend(true, defaults, parametros);
            $("#dialog:ui-dialog").dialog("destroy");
            $("#dialog-message p").html('<iframe src="' + options.html + '" name="print_modal" id="print_modal" width="99%" height="' + (options.height - 100) + '" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" style="overflow: auto;"></iframe>');
            $("#dialog-message").dialog({
                title: options.title,
                modal: true,
                resizable: true,
                position: "center",
                width: options.width,
                height: options.height,
                buttons: {
                    Fechar: function() {
                        $(this).dialog("close");
                    },
                    Imprimir: function() {
                        if ($.browser.msie) {
                            window.frames.print_modal.focus();
                            window.frames.print_modal.print();
                        } else {
                            window.frames.print_modal.focus();
                            window.frames.print_modal.print();
                        }
                    }
                },
                open: function() {
                    $(this).parent().find(".ui-dialog-buttonpane button:first-child").button({
                        icons: {
                            primary: "ui-icon-circle-close"
                        }
                    });
                    $(this).parent().find(".ui-dialog-buttonpane button:first-child").next().button({
                        icons: {
                            primary: "ui-icon-print"
                        }
                    });
                }
            });
            return false;
        }
    });
})(jQuery);

(function($) {
    $.fn.clear_text_limit = function() {
        return this.each(function() {
            this.onkeydown = this.onkeyup = null;
        });
    };

    $.fn.textLimit = function(limit, callback) {
        if (typeof callback !== "function") {
            var callback = function() {
            };

        }
        return this.each(function() {
            this.limit = limit;
            this.callback = callback;
            this.onkeydown = this.onkeyup = function() {
                this.value = this.value.substr(0, this.limit);
                this.reached = this.limit - this.value.length;
                this.reached = (this.reached == 0) ? true : false;
                return this.callback(this.value.length, this.limit, this.reached);
            };

        });
    };

})(jQuery);

(function($) {
    $.fn.extend({
        form_consultar: function() {
            var obj = this;
            var form = "#" + $(this).closest("form").attr("id");
            $(form).attr("method", "post");
            $(form).attr("onsubmit", "return false;");
            $(obj).click(function(a) {
                a.preventDefault();
                if ($(form).form_validate() == true) {
                    msg_sistema("Aguarde... Realizando operação.", "sucesso");
                    $(form).removeAttr("onsubmit");
                    $(form).attr("method", "post");
                    $(form).submit();
                    return true;
                } else {
                    return false;
                }
            });
        }
    });
})(jQuery);

/*
 * jQuery Master Dialog
 *
 * This plugins extends jQuery UI Dialog widget, adding minimize, restore and maximize buttons
 * Developed by Carlos Carvalhar - http://carvalhar.com when working at PixFly -> http://pixfly.com.br
 *
 * This code was based in two resources:
 * http://www.profissionaisti.com.br/2008/11/jquery-dialog-melhorias-interessantes  by Jackson Caset
 * http://old.nabble.com/How-to-%22properly%22-extend-the-jQuery-UI-Dialog-widget-----td24182676s27240.html
 *
 *
 * Depends:
 *	jQuery  (http://jquery.com)
 *  jQuery UI (http://jqueryui.com/demos/dialog)
 *
 */

(function($) {

    // $.widget("ui.mywidget", {_init: function() {}});
    var _init = $.ui.dialog.prototype._init;
    $.ui.dialog.prototype._init = function() {
        var self = this;
        _init.apply(this, arguments);

        uiDialogTitlebar = this.uiDialogTitlebar;
        this.originalSize();

        /* Adding maximize button */
        //if (self.options.maximized) {
        uiDialogTitlebar.append('<a href="#" id="dialog-maximize" class="ui-corner-all ui-dialog-titlebar-max" role="button"><span class="ui-icon ui-icon ui-icon-extlink">Max</span></a>');
        this.uiDialogTitlebarMax = $('#dialog-maximize', uiDialogTitlebar).hover(function() {
            $(this).addClass('ui-state-hover');
        }, function() {
            $(this).removeClass('ui-state-hover');
        }).mousedown(function(ev) {
            ev.stopPropagation();
        }).click(function() {
            self.maximize();
            return false;
        });

        /* Allow titlebar doubleclick to maximize/restore the dialog. */
        uiDialogTitlebar.bind("dblclick", function() {
            if (self.maximized) {
                self.restore();
            } else {
                self.maximize();
            }
        });
        //}

        /* Adding minimize button */

        //if (self.options.minimized) {
        uiDialogTitlebar.append('<a href="#" id="dialog-minimize" class="ui-corner-all ui-dialog-titlebar-min" role="button"><span class="ui-icon ui-icon ui-icon ui-icon-minus">Min</span></a>');
        this.uiDialogTitlebarMax = $('#dialog-minimize', uiDialogTitlebar).hover(function() {
            $(this).addClass('ui-state-hover');
        }, function() {
            $(this).removeClass('ui-state-hover');
        }).mousedown(function(ev) {
            ev.stopPropagation();
        }).click(function() {
            self.minimize();
            return false;
        });

        //}

        /* Adding restore button */

        //if (self.options.minimized || self.options.maximized ) {

        uiDialogTitlebar.append('<a href="#" id="dialog-restore" class="ui-corner-all ui-dialog-titlebar-rest" role="button"><span class="ui-icon ui-icon-newwin">Restore</span></a>');
        this.uiDialogTitlebarMin = $('#dialog-restore', uiDialogTitlebar).hover(function() {
            $(this).addClass('ui-state-hover');
        }, function() {
            $(this).removeClass('ui-state-hover');
        }).mousedown(function(ev) {
            ev.stopPropagation();
        }).click(function() {
            self.restore();
            return false;
        }).hide();
        //}

    };
    //$.ui.dialog.defaults.maximized = true;
    //$.ui.dialog.defaults.minimized = true;

    $.extend($.ui.dialog.prototype, {
        /* override resize */
        /*	resize: function() {
         alert("oi " + self.minimized);
         if (!self.minimized) {
         $.widget.prototype.destroy.apply(this, arguments);
         }
         },	*/

        /* Allow restore the dialog */
        restore: function() {
            this.maximized = false;
            /* reset both states (restored) */
            this.minimized = false;
            $('.ui-dialog-content').show();
            this.uiDialog.css({
                width: this.options.width,
                height: this.options.height
            });
            this.size();
            //$('#dialog-restore').css('right','1.5em');
            //this.adjustScrollContent();
            this.position(this.options.position);
            this.size();
            this.adjustScrollContent();
            //"ui-dialog-titlebar
            this.uiDialog.find('.ui-dialog-content').css({
                'height': (this.options.height - 104)
            });

            $('#dialog-maximize').show();
            $('#dialog-restore').hide();
            $('#dialog-minimize').show();
            this.uiDialog.css('position', 'absolute');
            /* this.uiDialog.data("resizable", true);
             this.uiDialog.data("draggable", true);
             this.uiDialog.addClass('ui-draggable ui-resizable ui-resizable-resizing');*/
        },
        /* Minimize to a custom position */
        minimize: function() {
            this.minimized = true;
            /* save the current state: minimized */
            this.maximized = false;
            //this.originalSize();
            $('.ui-dialog-content').hide();
            //$('#dialog-restore').css('right','2.8em');
            this.uiDialog.css('position', 'fixed');
            /* sticky the dialog at the page to avoid scrolling */
            this.uiDialog.animate({
                left: "10px",
                width: 250,
                height: 100,
                bottom: "10px"
            });
            this.size();
            this.adjustScrollContent();
            this.uiDialog.css('top', 'auto');
            /* needed because top has a default value and this breaks bottom value */
            $('#dialog-restore').show();
            $('#dialog-maximize').show();
            $('#dialog-minimize').hide();

            //this.uiDialog.dialog("close");

            /*this.uiDialog.data("resizable", false);
             this.uiDialog.data("draggable", false);
             this.uiDialog.removeClass('ui-draggable ui-resizable ui-resizable-resizing');
             this.options.resizable  = false;
             alert(this.options.resizable);*/
        },
        /* Maximize to the whole visible size of the window */
        maximize: function() {
            this.maximized = true;
            /* save the current state: maximized */
            this.minimized = false;
            //this.originalSize();
            $('.ui-dialog-content').show();
            $('#dialog-restore').css('right', '1.5em');
            this.uiDialog.animate({
                left: 3.5,
                top: 3.5,
                width: $(window).width() - 15,
                height: $(window).height() - 15
            });
            this.size();
            this.adjustScrollContent();
            this.uiDialog.find('.ui-dialog-content').css({
                'height': (($(window).height() - 15) - 104)
            });

            $('#dialog-restore').show();
            $('#dialog-maximize').hide();
            $('#dialog-minimize').show();
            this.uiDialog.css('position', 'absolute');
            this.uiDialog.data("resizable", true);
            this.uiDialog.data("draggable", true);
        },
        /* Store the size of dialog, before it gets minimized or maximized */
        originalSize: function() {
            this.options.height = this.uiDialog.height();
            this.options.width = this.uiDialog.width();
        },
        /* Saves all css related to the dialog position before maximize or minimize */
        position: function(pos) {
            var wnd = $(window), doc = $(document), pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), minTop = pTop;

            if ($.inArray(pos, ['center', 'top', 'right', 'bottom', 'left']) >= 0) {
                pos = [pos == 'right' || pos == 'left' ? pos : 'center', pos == 'top' || pos == 'bottom' ? pos : 'middle'];
            }
            if (pos.constructor != Array) {
                pos = ['center', 'middle'];
            }
            if (pos[0].constructor == Number) {
                pLeft += pos[0];
            } else {
                switch (pos[0]) {
                    case 'left':
                        pLeft += 0;
                        break;
                    case 'right':
                        pLeft += wnd.width() - this.uiDialog.width();
                        break;
                    default:
                    case 'center':
                        pLeft += (wnd.width() - this.uiDialog.width()) / 2;
                }
            }
            if (pos[1].constructor == Number) {
                pTop += pos[1];
            } else {
                switch (pos[1]) {
                    case 'top':
                        pTop += 0;
                        break;
                    case 'bottom':
                        pTop += wnd.height() - this.uiDialog.height();
                        break;
                    default:
                    case 'middle':
                        pTop += (wnd.height() - this.uiDialog.height()) / 2;
                }
            }

            // prevent the dialog from being too high (make sure the titlebar is accessible)
            pTop = Math.max(pTop, minTop);
            this.uiDialog.css({
                top: pTop,
                left: pLeft
            });
        },
        size: function() {
            var container = this.uiDialogTitlebar.parent(), titlebar = this.uiDialogTitlebar, content = this.element, tbMargin = parseInt(content.css('margin-top'), 10) + parseInt(content.css('margin-bottom'), 10), lrMargin = parseInt(content.css('margin-left'), 10) + parseInt(content.css('margin-right'), 10);

            content.height(container.height() - titlebar.outerHeight() - tbMargin/* More precision on scroll content */ - 8);
            content.width(container.width() - lrMargin);

        },
        /* Adjuste the content inside the dialog on maximize/restore */
        adjustScrollContent: function() {
            $('.ui-dialog-content').css({
                'width': '',
                'height': this.uiDialog.height() - 16,
                'overflow-x': 'hidden',
                'overflow-y': 'auto'
            });
        }
    });

})(jQuery);

$.fn.remove_tr = function() {
    $(this).closest("tr").addClass("excluida").delay(1000).fadeOut("slow", function() {
        $(this).remove();
        corLinhasTabela();
    });
};

$(document).ready(function() {
    if ($('.paginacao').html() == '') {
        $('.paginacao').hide();
    }

    // Toggle the dropdown menu's
    $(".dropdown .button, .dropdown button").click(function() {
        if (!$(this).find('span.toggle').hasClass('active')) {
            $('.dropdown-slider').slideUp();
            $('span.toggle').removeClass('active');
        }

        // open selected dropown
        $(this).parent().find('.dropdown-slider').slideToggle('fast');
        $(this).find('span.toggle').toggleClass('active');

        return false;
    });

    // Launch TipTip tooltip
    $('.tiptip a.button, .tiptip button').tipTip();

    // Close open dropdown slider by clicking elsewhwere on page
    $(document).bind('click', function(e) {
        if (e.target.id != $('.dropdown').attr('class')) {
            $('.dropdown-slider').slideUp();
            $('span.toggle').removeClass('active');
        }
    });
    corLinhasTabela();
});

function corLinhasTabela() {
    $(".tablesorter tbody tr").removeClass("even");
    $(".tablesorter").each(function() {
        $(this).find("tbody tr:odd").addClass("even");
    });
    $(".tablesorter tbody tr").mouseover(function() {
        $(this).addClass("odd");
    });
    $(".tablesorter tbody tr").mouseout(function() {
        $(this).removeClass("odd");
    });
}